package com.lzp.customview

import android.animation.ValueAnimator
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.util.Log
import android.view.View

/**
 * @describe:
 * @Author: lixiaopeng
 * @Date: 2020/11/12
 */
class TestView : View {

    private val TAG = "TestView"

    private var x = 0
    private val paint = Paint()
    constructor(context: Context?) : super(context)
    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs){
        paint.color = Color.BLUE
        paint.style = Paint.Style.FILL

        startTestAnimation()
    }


    private fun startTestAnimation(){


        val ofInt = ValueAnimator.ofInt(0, 100)
        ofInt.duration = 300
        ofInt.repeatCount  = ValueAnimator.INFINITE
        ofInt.addUpdateListener {
            x++
            postInvalidate()
        }
        ofInt.start()
    }


    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        Log.d(TAG, "onDraw: ")
        canvas?.drawCircle((x%10).toFloat(),(x%10).toFloat(),10f,paint)
    }
}